<?php

class m140113_135158_fill_users_table extends CDbMigration
{
    const TABLE = 'users';
    protected $socialNetworks = array('fb', 'vk');

    protected function getSocialNetwork()
    {
        return $this->socialNetworks[rand(0, 1)];
    }

    protected function getPhoneNumber()
    {
        $phoneNumber = '+380';

        for ($i = 0; $i < 9; $i++) {
            $phoneNumber .= rand(0, 9);
        }

        return $phoneNumber;
    }

    public function safeUp()
    {
        for ($i = 0; $i < 10; $i++) {
            $this->insert(self::TABLE, array(
                'first_name'     => 'TestFirstName' . $i,
                'last_name'      => 'TestLastName' . $i,
                'email'          => 'TestLastName' . $i . '@gmail.com',
                'phone'          => $this->getPhoneNumber(),
                'social_network' => $this->getSocialNetwork(),
                'create_time'    => date('Y-m-d H:i:s', time() + 40000 * $i),
            ));
        }
    }

    public function safeDown()
    {
        $this->delete(self::TABLE, array('first_name like "TestFirstName%"'));
    }
}
